/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 刘远望
 * Date: 2025-05-01
 * Time: 12:59
 */
//通配符的上界
class Food {

}
class Fruit extends Food {

}
class Apple extends Fruit {

}
class Banana extends Fruit {

}
class Message2<T> { // 设置泛型
    private T message ;

    public T getMessage() {
        return message;
    }

    public void setMessage(T message) {
        this.message = message;
    }

}

public class TestDemo2 {
    // 此时使用通配符"?"描述的是它可以接收任意类型，但是由于不确定类型，所以无法修改
    public static void fun(/*传入类型*/Message2<? extends Fruit> temp){
        //temp.setMessage(new Banana()); //仍然无法修改！
        //temp.setMessage(new Apple()); //仍然无法修改！
        System.out.println(temp.getMessage());
    }

    public static void main(String[] args) {
        Message2<Apple> message = new Message2<>() ;
        message.setMessage(new Apple());
        fun(message);

        Message2<Banana> message2 = new Message2<>() ;
        message2.setMessage(new Banana());
        fun(message2);

    }

}
